<template>
    <!-- 漏斗图 -->
    <div class="app-container">
        <el-row :gutter="30" :style="{height: '400px', width: '600px'}">
            <div class="chart" ref="chart" :style="{height:'100%',width:'100%'}"></div>
        </el-row>
    </div>
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from '@/views/dashboard/mixins/resize'

export default {
    name: 'ChartFunnel',
    mixins: [resize],
    data() {
        return {
            chart: null
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.initChart()
        })
    },
    beforeDestroy() {
        if (!this.chart) {
            return
        }
        this.chart.dispose()
        this.chart = null
    },
    methods: {
        initChart() {
            this.chart = echarts.init(this.$refs['chart'], 'macarons')
            this.setOptions(this.chartData)
        },
        setOptions() {
            this.chart.setOption({
                title: {
                    text: '某站点用户访问来源',
                    subtext: '纯属虚构',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item', //触发类型,默认数据触发，可选为:'item' | 'axis'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    top: 'center',
                    data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
                },
                toolbox: {
                    show: true,
                    feature: {
                        mark: {
                            show: true
                        },
                        dataView: {
                            show: true,
                            readOnly: true
                        },
                        restore: {
                            show: true
                        },
                        saveAsImage: {
                            show: true
                        }
                    }
                },
                series: [
                    {
                        name: '访问来源',
                        type: 'funnel',
                        x: '30%',
                        x2: '15%',
                        y2: '10%',
                        max: 100,
                        itemStyle: {  //图形样式，可设置图表内图形的默认样式和强调样式（悬浮时样式）：
                            normal: {
                                labelLine: {  //标签视觉引导线，默认显示
                                    show: false
                                }
                            },
                            emphasis: {
                                labelLine: {
                                    show: false
                                }
                            }
                        },
                        data: [
                            {
                                value: 80,
                                name: '直接访问'
                            },
                            {
                                value: 60,
                                name: '邮件营销'
                            },
                            {
                                value: 40,
                                name: '联盟广告'
                            },
                            {
                                value: 20,
                                name: '视频广告'
                            },
                            {
                                value: 100,
                                name: '搜索引擎'
                            }
                        ]
                    }
                ]
            });
        }
    }
}
</script>